package com.you.mavenbuildtest.dbwork;

import org.apache.commons.io.IOUtils;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Random;

public class ProdSql {
    public static void main(String[] args) {
        FileOutputStream out = null;
        try {
            out = new FileOutputStream("C:\\E\\insert20w.sql", true);
            for (int i = 0; i < 200000; i++) {
                String sql = String.format("insert DELAYED into test_delete VALUES('%s','%s','%s');%s",
                        getStringRandom(64),getStringRandom(6),getChinesRandom(4),"\n");

                IOUtils.write(sql, out);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public static String getStringRandom(int length) {

        StringBuilder val = new StringBuilder();
        Random random = new Random();
        //length为几位密码
        for(int i = 0; i < length; i++) {
            //输出字母还是数字
            int chatTypa = random.nextInt(3);
            switch (chatTypa){
                case 0:
                    //数字
                    val.append(random.nextInt(10));
                    break;
                case 1:
                    //小写字母
                    val.append((char) (random.nextInt(26) + 97));
                    break;
                case 2:
                    //大写字母
                    val.append((char) (random.nextInt(26) + 65));
                    break;
            }
        }
        return val.toString();
    }

    public static String getChinesRandom(int length){
        StringBuilder val = new StringBuilder();
        for(int i=0;i<length;i++){
            val.append((char) (0x4e00 + (int) (Math.random() * (0x9fa5 - 0x4e00 + 1))));
        }
        return val.toString();
    }
}
